<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of report
 *
 * @author Константин Охотник
 */

class Authorization extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('atrz');
    }
    public function index()
    {
        $s= $this->session->getSession();
        if(!isset($s['userdata']) && !$this->input->post())
        {
            $this->crud->display('authorization.tpl'); 
        }
        
        if($this->input->post())
        {
            $data = $this->input->post();
            $result = $this->atrz->iseetUser($data['login'], $data['password']);

           if($result)
            {
                $this->session->setUserData( $result[0]['id'], array( $result[0]['login'],$result[0]['id'],$result[0]['id_access'], $result[0]['name'],$result[0]['first_name'], $result[0]['second_name'] ));
                redirect(site_url("client/"), 'refresh');
            }
            if(empty($result))
            {
               $this->crud->display('authorization.tpl'); 
            }
        }
        
        if(isset($s['userdata']))
        {
            redirect(site_url("client/"), 'refresh');
        }
    }
    
    public function destroy()
    {
        $this->session->destruct();
        redirect(site_url(), 'refresh');
    }
}